# 生产者消费者模式
from queue import Queue
from threading import Thread
import time

# 生产者
class CreateFun (Thread):
    def __init__ (self,name,queue):
        Thread.__init__(self,name=name)
        self.queue = queue
    def run(self):
        for i in range(6):
            self.queue.put('key'+str(i))
            print('key'+str(i),'--生产的数据')
            time.sleep(1)
        print('生产者生产完毕')

class ConsumerFun (Thread) :
    def __init__ (self,name,queue):
        Thread.__init__(self,name=name)
        self.queue = queue
    def run (self):
        for i in range(6):
            num = self.queue.get()
            print(f'now get data is {num}')
        print(' get data is done')

if __name__ == '__main__':
    qu = Queue()
    p1 = CreateFun('ts', qu)
    p2 = ConsumerFun('sy', qu)
    p1.start()
    p2.start()
    p1.join()
    p2.join()
    print("全部结束")
